<!DOCTYPE html>
<html lang="zh">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>三职院考勤</title>
    <meta name="keywords" content="考勤 ">
    <meta name="description" content="考勤">
    <meta name="author" content="">
    <link rel="stylesheet" type="text/css" href="./static/bootstrap/css/bootstrap.min.css">

    <link rel="stylesheet" type="text/css" href="./static/css/style.css">
    <link rel="icon" href="./static/img/logo.png" type="image/png">
</head>
<style>
    body,
    html {
        margin: 0;
        padding: 0;
    }

    .title_label {
        left: 48px;
        top: 5px;
        height: 29px;
        color: rgba(255, 255, 255, 1);
        font-size: 20px;
        text-align: left;
        font-family: PingFangSC-bold;
    }

    .header_main {
        width: 100%;
        margin: auto;
        background-image: url(/static/img/head_bg.png);
        background-position: top -110px right 0px;
        height: auto;
        padding-top: 20px;
        padding-bottom: 20px;
        background-size: cover;
        background-size: 100%;
        background-repeat: no-repeat;

    }

    .row {
        margin-top: 10px;
    }

    .m-l-30 {
        margin-left: 30px;
    }

    .submit {

        color: white;
        background-color: #17ad74;
        width: 100%;
        height: 50px;
        border-radius: 10px;
        border: 0px;
    }
</style>

<body id="mainAPP" class="header_main">
    <header id="home" class="container ">
        <div class="row   ">
            <div class=" col-12">
                <h1 class="title_label">
                    <strong> 三峡职业学院考勤登记表单 </strong>
                </h1>
            </div>
        </div>
    </header>
    <div class="container " id="mainDiv" style="margin-top:60px;">

        <div class="row ">
            <div class=" offset-md-1 col-lg-8 col-md-9 ">

                <input class="form-check-input" type="radio" name="classname" value="1" checked>
                <label class="form-check-label" for="1">
                    21级云计算 01 班
                </label>
                <input class="form-check-input" type="radio" name="classname" value="2">
                <label class="form-check-label" for="2">
                    21级云计算 02 班
                </label>
            </div>
        </div>
        <div class="row  margin-top-20 ">
            <div class=" offset-md-1 col-lg-8 col-md-9 ">
                <label for="username" class="form-label">姓名</label>
                <input type="text" class="form-control" id="username" placeholder="填写本人真实姓名">
            </div>
        </div>

        <div class="row  ">
            <div class=" offset-md-1 col-lg-8 col-md-9 ">
                <label for="sn" class="form-label">学号</label>
                <input type="text" class="form-control" id="sn" placeholder="填写本人学号">
            </div>
        </div>
        <div class="row  ">
            <div class=" offset-md-1 col-lg-8 col-md-9 ">
                <label for="tel" class="form-label">电话</label>
                <input type="text" class="form-control" id="tel" placeholder="填写本人电话号码">
            </div>
        </div>
        <div class="row  ">
            <div class=" offset-md-1 col-lg-8 col-md-9 ">
                <label for="classroom" class="form-label">地址</label>
                <input type="text" class="form-control" id="classroom" placeholder="填写现在你的教室名，例如信科楼607">
            </div>
        </div>
        <div class="row  ">
            <div class=" offset-md-1 col-lg-8 col-md-9 ">
                <button type="button" class="submit" data-bs-toggle="modal" data-bs-target="#exampleModal"
                    onclick="submitHandler() "> 提交 </button>
            </div>
        </div>



    </div>
    <div class="modal" id="exampleModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">确认信息</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div id="userinfoDiv">信息错误</div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="save() "
                        data-bs-dismiss="modal">确定保存</button>
                </div>
            </div>
        </div>
    </div>

    <script src="./static/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="./static/js/axios.min.js"></script>
    <script type="text/javascript">
        let userInfo = new Object();
        function submitHandler() {
            let classlist = document.getElementsByName("classname");
            classlist.forEach(classitem => {
                if (classitem.checked) {
                    userInfo.Classid = parseInt(classitem.value, 10);
                    userInfo.Classname
                    if (userInfo.Classid == 1) {
                        userInfo.Classname = " 21级云计算01班级"
                    } else {
                        userInfo.Classname = " 21级云计算02班级"
                    }
                }
            });
            userInfo.Name = document.getElementById("username").value;
            userInfo.Sn = document.getElementById("sn").value;
            userInfo.Tel = document.getElementById("tel").value;
            userInfo.Classroom = document.getElementById("classroom").value;
            document.getElementById("userinfoDiv").innerHTML =
                `<label>班级:` + userInfo.Classname + `</label><br/>` +
                `<label>姓名:` + userInfo.Name + `</label><br/>` +
                `<label>电话:` + userInfo.Tel + `</label><br/>` +
                `<label>学号:` + userInfo.Sn + `</label><br/>` +
                `<label>位置:` + userInfo.Classroom + `</label><br/>`;
        }

        function save() {
            axios.post('/api/classmates/signIn/', userInfo).then(function (response) {
                if (response.data.code > 0) {
                    var result =
                        `<div style="text-align:center ;">姓名:` + userInfo.Name + `学号:` + userInfo.Sn +  `IP:` + response.data.user.IP + `</div><hr>` +
                        ` <table style="border:1px solid black ; width:100%;padding:10px">
                    <tr   style="border:1px solid black ; width:100%;padding:10px">
                        <th>上课地点</th> <th>签到时间</th>
                    </tr>`; 
                    response.data.data.forEach(item => {
                        result += `<tr> `
                        result += `  <td>` + item.Classroom + `</td>`
                        result += `  <td>` + item.Createtime + `</td>`
                        result += `</tr> `
                    });
                    result += ` </table>`;
                    document.getElementById("mainDiv").innerHTML = result;
                    alert("填写成功")
                } else {
                    alert(response.data.data)
                }
            }).catch(function (error) {
                alert(error)
            });
        }


    </script>

</body>

</html>